/**
 * 
 */
package org.dse.analysis.dict;

/**
 * This class represents the result of a search action in the dictionary. The
 * result may be match perfectly, match only a part from begin, or totally
 * unmatch.
 * 
 * @author zhangchen
 * 
 */
public class Hit {

	private static final int MATCH = 1;
	private static final int PREFIX_MATCH = 0x10;
	private static final int UNMATCH = 0x100;
	private int hitState;
	private WordType wordType;

	public Hit() {
		hitState = 0;
	}

	/**
	 * Judge the search result is a perfect match.
	 * 
	 * @return a boolean value to show whether it is a perfect match
	 */
	public boolean isMatch() {
		return (hitState & MATCH) > 0;
	}

	/**
	 * Set the search result as a perfect match.
	 */
	public void setMatch() {
		hitState = hitState | MATCH;
	}

	/**
	 * Judge the search result is a perfect match and a prefix match as well.
	 * 
	 * @return a boolean value to show whether it is a perfect and prefix match
	 */
	public boolean isMatchAndContinue() {
		return (hitState & MATCH) > 0 && (hitState & PREFIX_MATCH) > 0;
	}

	/**
	 * Judge the search result is a prefix match.
	 * 
	 * @return a boolean value to show whether it is a prefix match
	 */
	public boolean isPrefixMatch() {
		return (hitState & PREFIX_MATCH) > 0;
	}

	/**
	 * Set the search result as a prefix match.
	 */
	public void setPrefixMatch() {
		hitState = hitState | PREFIX_MATCH;
	}

	/**
	 * Judge the search result is an unmatch.
	 * 
	 * @return a boolean value to show whether it is an unmatch
	 */
	public boolean isUnmatch() {
		return (hitState & UNMATCH) > 0;
	}

	/**
	 * Set the search result as an unmatch.
	 */
	public void setUnmatch() {
		hitState = UNMATCH;
	}

	/**
	 * Get the word type of this search action.
	 * 
	 * @return the word type
	 */
	public WordType getWordType() {
		return wordType;
	}

	/**
	 * Set the word type of this search action.
	 * 
	 * @param wordType
	 *            the current word type
	 */
	public void setWordType(WordType wordType) {
		this.wordType = wordType;
	}

	/**
	 * Get the hit state, may be match, prefix match, unmatch.
	 * 
	 * @return an integer representing the hit state
	 */
	public int getHitState() {
		return hitState;
	}
}